<template>
    <table>
        <tr>
            <td>用户名</td>
            <td>
                <input type="text" v-model="info.name"/>
            </td>
        </tr>
        <tr>
            <td>密码</td>
            <td>
                <input type="password" v-model="info.pwd"/>
            </td>
        </tr>
        <tr>
            <td>确认密码</td>
            <td>
                <input type="password" v-model="pwd2"/>
            </td>
        </tr>
        <tr>
            <td>手机号</td>
            <td>
                <input type="text" v-model="info.phone"/>
            </td>
        </tr>
        <tr>
            <td>邮箱</td>
            <td>
                <input type="text" v-model="info.email"/>
            </td>
        </tr>
        <tr>
            <td></td>
            <td>
                <input type="button" value="保存" @click="add"/>
            </td>
        </tr>
    </table>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import axios from 'axios';
import router from '@/router';
const info=ref({
    "id": 0,
  "name": "",
  "pwd": "",
  "email": "",
  "phone": "",
  
})
const pwd2=ref("")
const add=()=>{
    if(info.value.name==""){
        alert("用户名不能为空");
        return;
    }
    if(info.value.pwd!=pwd2.value){
        alert("密码不一致");
        return;
    }
    axios.post("https://localhost:7258/api/user/useradd",info.value).then(res=>{
        if(res.data>0){
            alert('成功');
            router.push("/usershow");
        }
        else{
            alert('失败');
        }
    })
}
</script>

<style scoped>

</style>